package com.haier.os.security.core.validate.code;

import java.time.LocalDateTime;

/**
 * 封装验证码属性
 */
public class ValidateCode {
    private String code;
    private LocalDateTime expireTime;

    /**
     * 初始化验证码
     *
     * @param code     验证码code
     * @param expireIn 过期间隔时间，单位秒
     */
    public ValidateCode(String code, int expireIn) {
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    /**
     * 验证码是否过期
     *
     * @return true 过期 false 未过期
     */
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }
}
